package com.hadluo.qq.client.ui;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class IconGenerator {
    private static final int ICON_SIZE = 24;

    public static void main(String[] args) {
        generateFriendsIcon();
        generateAddFriendIcon();
        generateGroupListIcon();
        generateCreateGroupIcon();
    }

    private static void generateFriendsIcon() {
        BufferedImage image = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 设置白色
        g2d.setColor(Color.WHITE);

        // 绘制三个小人图标
        int[] xPoints = {6, 12, 18};
        for (int x : xPoints) {
            // 头部（圆形）
            g2d.fillOval(x - 2, 4, 4, 4);
            // 身体（矩形）
            g2d.fillRect(x - 3, 9, 6, 8);
        }

        g2d.dispose();

        // 保存图标
        try {
            File resourcesDir = new File("src/main/resources/icons");
            if (!resourcesDir.exists()) {
                resourcesDir.mkdirs();
            }
            ImageIO.write(image, "PNG", new File(resourcesDir, "friends.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void generateAddFriendIcon() {
        BufferedImage image = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 设置白色
        g2d.setColor(Color.WHITE);

        // 绘制加号
        g2d.setStroke(new BasicStroke(2));
        // 垂直线
        g2d.drawLine(12, 6, 12, 18);
        // 水平线
        g2d.drawLine(6, 12, 18, 12);

        g2d.dispose();

        // 保存图标
        try {
            File resourcesDir = new File("src/main/resources/icons");
            if (!resourcesDir.exists()) {
                resourcesDir.mkdirs();
            }
            ImageIO.write(image, "PNG", new File(resourcesDir, "add_friend.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void generateGroupListIcon() {
        BufferedImage image = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 设置白色
        g2d.setColor(Color.WHITE);

        // 绘制群组图标（三个重叠的圆形）
        g2d.fillOval(4, 8, 8, 8);  // 左下
        g2d.fillOval(8, 4, 8, 8);  // 右上
        g2d.fillOval(12, 8, 8, 8); // 右下

        g2d.dispose();

        // 保存图标
        try {
            File resourcesDir = new File("src/main/resources/icons");
            if (!resourcesDir.exists()) {
                resourcesDir.mkdirs();
            }
            ImageIO.write(image, "PNG", new File(resourcesDir, "group_list.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void generateCreateGroupIcon() {
        BufferedImage image = new BufferedImage(ICON_SIZE, ICON_SIZE, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 设置白色
        g2d.setColor(Color.WHITE);

        // 绘制群组基本图标（两个重叠的圆形）
        g2d.fillOval(4, 8, 8, 8);  // 左
        g2d.fillOval(10, 8, 8, 8); // 右

        // 绘制加号
        g2d.setStroke(new BasicStroke(2));
        // 垂直线
        g2d.drawLine(18, 4, 18, 10);
        // 水平线
        g2d.drawLine(15, 7, 21, 7);

        g2d.dispose();

        // 保存图标
        try {
            File resourcesDir = new File("src/main/resources/icons");
            if (!resourcesDir.exists()) {
                resourcesDir.mkdirs();
            }
            ImageIO.write(image, "PNG", new File(resourcesDir, "create_group.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}